package com.aboo.dao.impl;

import java.util.List;

import com.aboo.dao.BaseSqlMapDao;
import com.aboo.dao.RoleDao;
import com.aboo.po.AdminUserPO;
import com.aboo.po.MenuPO;
import com.aboo.po.Page;
import com.aboo.po.RolePO;
import com.aboo.pub.constant.Constant;

public class RoleDaoImpl extends BaseSqlMapDao implements RoleDao {

	public Integer save(RolePO po) throws Exception {
		return (Integer) getSmcTemplate().insert("Role.insertRole", po);
	}

	public void delete(Integer id) throws Exception {
		RolePO tmp = new RolePO();
		tmp.setId(id);
		tmp.setInUse(Constant.INUSE_NO);
		getSmcTemplate().update("Role.updateRole", tmp);
	}

	public RolePO find(RolePO po) throws Exception {
		return (RolePO) getSmcTemplate().queryForObject("Role.selectRoleList", po);
	}

	public Integer findCount(RolePO po) throws Exception {
		return (Integer) getSmcTemplate().queryForObject("Role.selectRoleCount", po);
	}

	public List<RolePO> findList(RolePO po, Page page)
			throws Exception {
		if (page != null) {
			po.setBeginIndex(page.getBeginRecordIndex());
			po.setEndIndex(page.getEndRecordIndex());
		}
		po.addSort("ID", Constant.SORT_ASC);
		return getSmcTemplate().queryForList("Role.selectRoleList", po);
	}

	public void update(RolePO po) throws Exception {
		getSmcTemplate().update("Role.updateRole", po);
	}

	public List<MenuPO> findMenuById(Integer id) throws Exception {
		return getSmcTemplate().queryForList("Role.selectMenuById", id);
	}

	public List<AdminUserPO> findUserById(Integer id) throws Exception {
		return getSmcTemplate().queryForList("Role.selectUserById", id);
	}

}
